package com.googlecode.FWT.view.buttons.forward
{
	import com.googlecode.FWT.core.NotificationNames;
	import com.googlecode.FWT.model.ProjectDataProxy;
	import com.googlecode.FWT.view.buttons.back.ButtonMediator;
	
	import flash.events.MouseEvent;
	
	import mx.controls.Button;
	
	import org.puremvc.as3.interfaces.INotification;
	
	/**
	 * Integrates the BackButton view component with the PureMVC framework.
	 * 
	 */
	public class ForwardButtonMediator extends ButtonMediator
	{
		/**
		 * PureMVC identifier 
		 */
		public static const NAME:String = "ForwardButtonMediator";
		
		/**
		 * Constructor. 
		 * @param viewComponent
		 * 
		 */
		public function ForwardButtonMediator(viewComponent:Button)
		{
			super(NAME, viewComponent);
		}
			
		/**
		 * Sends notification that forward button has been clicked. 
		 * @param evt
		 * 
		 */
		override protected function onButtonClick(evt:MouseEvent):void
		{
			sendNotification(NotificationNames.GO_FORWARD);
		}
		
		/**
		 * Notify interest in page change events. 
		 * @return 
		 * 
		 */
		override public function listNotificationInterests():Array
		{
			var list:Array = super.listNotificationInterests();
			list.push(ProjectDataProxy.PAGE_INDEX_CHANGED);
			
			return list;
		}
		
		/**
		 * When a paged is changed, the forward button needs to be made invisible, if on the last page. 
		 * @param notification
		 * 
		 */
		override public function handleNotification(notification:INotification):void
		{
			// if the button is on the last page, make it invisible
			var proxy:ProjectDataProxy = facade.retrieveProxy(ProjectDataProxy.NAME) as ProjectDataProxy;
			var numPages:int = proxy.numPages;
			
			if(notification.getBody() as int == numPages -1)
			{
				viewRef.visible = false;
			}else
			{
				viewRef.visible = true;
			}
		} 
	}
}